//
//  NSString+LenWid.m
//  EduOnLine
//
//  Created by Mac on 2019/11/14.
//  Copyright © 2019 eduonline. All rights reserved.
//

#import "NSString+LenWid.h"

@implementation NSString (LenWid)

#pragma mark - 根据一定高度/宽度返回宽度/高度

// 根据文字（宽度/高度一定,字号一定的情况下）  算出高度/宽度
+ (CGSize)getStringSizeWith:(NSString *)goalString
             withStringFont:(CGFloat)tfont
          withWidthOrHeight:(CGFloat)tfixedSize
               isWidthFixed:(BOOL)isWidth{
    
    CGSize   sizeC ;
    
    if (isWidth) {
        sizeC = CGSizeMake(tfixedSize ,MAXFLOAT);
    }else{
        sizeC = CGSizeMake(MAXFLOAT ,tfixedSize);
    }
    
    CGSize   sizeFileName = [goalString boundingRectWithSize:sizeC
                                                     options:NSStringDrawingUsesLineFragmentOrigin
                                                  attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:tfont]}
                                                     context:nil].size;
    
    return sizeFileName;
}

-(CGFloat)getStringWidthFont:(UIFont*)font limitHeight:(CGFloat)limitHeight;
{
    CGSize size = [self boundingRectWithSize:CGSizeMake(MAXFLOAT, limitHeight)
                                                     options:NSStringDrawingUsesLineFragmentOrigin
                                                  attributes:@{NSFontAttributeName:font}
                                                     context:nil].size;
    return size.width+1;
}

-(CGFloat)getStringHeightFont:(UIFont*)font limitWidth:(CGFloat)limitWidth
{
    CGSize size = [self boundingRectWithSize:CGSizeMake(limitWidth,MAXFLOAT)
                                                     options:NSStringDrawingUsesLineFragmentOrigin
                                                  attributes:@{NSFontAttributeName:font}
                                                     context:nil].size;
    return size.height+1;
}

+(NSString *)getLetter:(NSString *)strInput{
    
    if ([strInput length]) {
        NSMutableString *ms = [[NSMutableString alloc] initWithString:strInput];
        CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformMandarinLatin, NO);
        CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformStripDiacritics, NO);
        
        NSArray *pyArray = [ms componentsSeparatedByString:@" "];
        if(pyArray && pyArray.count > 0){
            NSString *str = @"";
            for (NSString *strTemp in pyArray) {
                str = [str stringByAppendingString:[strTemp substringToIndex:1]];
            }
            
            return [str uppercaseString];
        }
        
        ms = nil;
    }
    
    return nil;
}


@end
